package com.clickpaas.materialsprocurement.service.Impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.*;
import com.clickpaas.materialsprocurement.common.Response.CommonCode;
import com.clickpaas.materialsprocurement.common.Response.ResponseResult;
import com.clickpaas.materialsprocurement.entity.*;
import com.clickpaas.materialsprocurement.service.*;
import com.clickpaas.materialsprocurement.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


@Service
@Slf4j
public class ControllerServiceImpl implements ControllerService {

    @Resource
    private MaterialsService materialsService;
    @Resource
    private ReLineService reLineService;
    @Resource
    private SharedInventService sharedInventService;
    @Resource
    private CostCenterService costCenterService;
    @Resource
    private UnitService unitService;
    @Resource
    private InquiryOrderLineService inquiryOrderLineService;
    @Resource
    private SupplierInfoService supplierInfoService;
    @Resource
    private PurchaseLineService purchaseLineService;
    @Resource
    private SelectionService selectionService;
    @Resource
    private PurchaseOrderService purchaseOrderService;
    @Resource
    private StockInOrderService stockInOrderService;
    /**
     * 查询请购单行数据
     *
     * @param materialsEntity
     * @return
     */
    @Override
    public ResponseResult getReqLineMaterialsInfo(MaterialsEntity materialsEntity) {
        /**
         * 查询物料数据
         */
        List<STDmaterielDTO> materialsInfo = materialsService.getMaterialsInfo(materialsEntity);
        if (null ==materialsInfo || materialsInfo.size()<=0){
            return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        }
        ArrayList<Object> reList = new ArrayList<>();

        /**
         * 多线程处理数据
         */
        ExecutorService pool = Executors.newCachedThreadPool();
        CountDownLatch latch = new CountDownLatch(materialsInfo.size());
        /**
         * 请购单行数据
         */
        for (STDmaterielDTO maters : materialsInfo){
            /**
             * 开启子线程
             */
            Runnable run = new Runnable() {
                public void run() {
                    try {
                        if (StringUtils.isBlank(maters.getId())){
                            return;
                            //continue;
                        }
                        ReqLineEntity reqLineEntity = new ReqLineEntity();
                        reqLineEntity.setMateriel(maters.getId());
                        List<PMSpurchaseApplyLineDTOResponse> applyLine = reLineService.getReLineInfo(reqLineEntity);
                        if (null != applyLine && applyLine.size()>0){
                            HashMap<String, Object> map = new HashMap<>();
                            ArrayList<Object> Relist = new ArrayList<>();
                            /**
                             * 请购单行
                             */
                            List<ReqLineEntity> reqLineEntities = reLineService.ApplyLineDataConver(applyLine);

                            /**
                             * 多线程处理数据
                             */
                            ExecutorService reqPool = Executors.newCachedThreadPool();
                            CountDownLatch reqLatch = new CountDownLatch(reqLineEntities.size());
                            for (ReqLineEntity entity : reqLineEntities){
                                /**
                                 * 开启子线程
                                 */
                                Runnable run = new Runnable() {
                                    public void run() {
                                        try {
                                            HashMap<String, Object> resultMap = new HashMap<>();
                                            if (null != entity.getCostCenter()
                                                    && null != entity.getSupplier()) {

                                                /**
                                                 * 成本中心
                                                 */
                                                CostCenterEntity costCenterEntity = new CostCenterEntity();
                                                costCenterEntity.setId(entity.getCostCenter().toString());
                                                List<CostCenterDTOResponse> costCenterInfo = costCenterService.getCostCenterInfo(costCenterEntity);
                                                if (null == costCenterInfo || costCenterInfo.size() <= 0) return;
                                                List<CostCenterEntity> costCenterEntities = costCenterService.costCenterDataConver(costCenterInfo);
                                                if (null == costCenterEntities || costCenterEntities.size() <= 0) return;
                                                resultMap.put("costCenter", costCenterEntities.get(0));
                                                /**
                                                 * 供应商
                                                 */
                                                SupplierInformationEntity supplierInformationEntity = new SupplierInformationEntity();
                                                supplierInformationEntity.setId(entity.getSupplier().toString());
                                                List<SupplierInformationDTO> supplierInfoInfo = supplierInfoService.getSupplierInfoInfo(supplierInformationEntity);
                                                if (null == supplierInfoInfo || supplierInfoInfo.size() <= 0) return;
                                                List<SupplierInformationEntity> supplierInformationEntities = supplierInfoService.supplierInfoDataConver(supplierInfoInfo);
                                                if (null == supplierInformationEntities || supplierInformationEntities.size() <= 0) return;
                                                resultMap.put("supplier", supplierInformationEntities.get(0));
                                                /**
                                                 * 请购单行
                                                 */
                                                resultMap.put("purchaseApplyLine",entity);
                                                Relist.add(resultMap);
                                            }
                                        }catch(Exception e){
                                            log.info("多线程转换报错,查询对象是：【{}】,请检查：【{}】",entity,e);
                                        } finally {
                                            reqLatch.countDown();
                                        }
                                    }
                                };
                                reqPool.execute(run);
                            }try {
                                reqLatch.await(10, TimeUnit.SECONDS);
                            } catch (InterruptedException e) {
                                log.info("多线程转换报错,请检查：【{}】",e);
                            }finally {
                                reqPool.shutdown();
                            }
                            if (Relist.size()>0){
                                map.put("result",Relist);
                                /**
                                 * 物料资料
                                 */
                                MaterialsEntity materialsEntity1 = materialsService.MaterialDataConver(maters);
                                map.put("materials",materialsEntity1);
                                reList.add(map);
                            }
                        }
                    }catch(Exception e){
                        log.info("多线程转换报错,查询对象是：【{}】,请检查：【{}】",maters,e);
                    } finally {
                        latch.countDown();
                    }
                }
            };
            pool.execute(run);
        }try {
            latch.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.info("多线程转换报错,请检查：【{}】",e);
        }finally {
            pool.shutdown();
        }
        return new ResponseResult(CommonCode.SUCCESS,reList);
    }

    /**
     * 查询物料数据
     *
     * @return
     */
    @Override
    public ResponseResult getMaterialsInfo() {
        /**
         * 查询物料数据
         */
        List<STDmaterielDTO> materialsInfo = materialsService.getMaterialsInfo(new MaterialsEntity());
        if (null ==materialsInfo || materialsInfo.size()<=0){
            return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        }
        List<MaterialsEntity> materialsEntities = materialsService.MaterialDataListConver(materialsInfo);
        if (null == materialsEntities || materialsEntities.size()<=0){
            return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        }
        return new ResponseResult(CommonCode.SUCCESS,materialsEntities);
    }

    /**
     * 查询共享库存
     *
     * @param materialsEntity
     * @return
     */
    @Override
    public ResponseResult getSharedInventoryInfo(MaterialsEntity materialsEntity) {
        /**
         * 查询物料数据
         */
        List<STDmaterielDTO> materialsInfo = materialsService.getMaterialsInfo(materialsEntity);
        if (null ==materialsInfo || materialsInfo.size()<=0){
            return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        }
        ArrayList<Object> reList = new ArrayList<>();
        /**
         * 共享库存数据
         */
        for (STDmaterielDTO maters : materialsInfo){
            if (StringUtils.isBlank(maters.getId())){
                continue;
            }
            HashMap<String, Object> ReHashMap = new HashMap<>();
            ReHashMap.put("maters",maters.getId());

            SharedInventEntity sharedInventEntity = new SharedInventEntity();
            sharedInventEntity.setMaterialName(maters.getId());

            List<ShareWarehouseDTOResponse> sharedInventInfo = sharedInventService.getSharedInventInfo(sharedInventEntity);
            if (null != sharedInventInfo && sharedInventInfo.size()>0){
                /**
                 * 共享库存对象
                 */
                List<SharedInventEntity> sharedInventEntities = sharedInventService.SharedInventDataConver(sharedInventInfo);

                List<Object> ShareList = new ArrayList<>();
                for (SharedInventEntity sharedEntity : sharedInventEntities){
                    HashMap<String, Object> map = new HashMap<>();
                    if (null != sharedEntity.getCostCenter()
                            && null != sharedEntity.getMaterialName()){
                        /**
                         * 成本中心
                         */
                        CostCenterEntity costCenterEntity = new CostCenterEntity();
                        costCenterEntity.setId(sharedEntity.getCostCenter().toString());
                        List<CostCenterDTOResponse> costCenterInfo = costCenterService.getCostCenterInfo(costCenterEntity);
                        if (null ==costCenterInfo || costCenterInfo.size()<=0)continue;
                        List<CostCenterEntity> costCenterEntities = costCenterService.costCenterDataConver(costCenterInfo);
                        if (null ==costCenterEntities || costCenterEntities.size()<=0)continue;
                        map.put("costCenter",costCenterEntities.get(0));

                        /**
                         * 物料资料
                         */
                        MaterialsEntity materialsEntity1 = materialsService.MaterialDataConver(maters);
                        if (null == materialsEntity1)continue;
                        map.put("materials",materialsEntity1);

                        /**
                         * 单位
                         */
                        UnitEntity unitEntity = new UnitEntity();
                        unitEntity.setId(materialsEntity1.getMaterielUnit().toString());
                        List<UnitDTOResponse> unitInfo = unitService.getUnitInfo(unitEntity);
                        if (null == unitInfo && unitInfo.size()<=0)continue;
                        List<UnitEntity> unitEntities = unitService.unitDataConver(unitInfo);
                        if (null == unitEntities && unitEntities.size()<=0)continue;
                        map.put("unit",unitEntities.get(0));
                        /**
                         * 共享库存对象
                         */
                        map.put("sharedInvent",sharedEntity);

                    }
                    if (null != map){
                        ShareList.add(map);
                    }
                }
                if (ShareList.size()>0){
                    ReHashMap.put("result",ShareList);
                }
                if (null != ReHashMap){
                    reList.add(ReHashMap);
                }
            }
        }
        return new ResponseResult(CommonCode.SUCCESS,reList);
    }

    /**
     * 采购订单行数据入表
     *
     * @param json
     * @return
     */
    @Override
    public ResponseResult insertPurchaseOrderLineInfo(String json) {
        if (StringUtils.isBlank(json))return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参(物料名称、供应商、采购订单)！");
        JSONObject jsonObject = JsonUtil.jsonStrToJson(json);
        PurchaseOrderLineEntity purchaseOrderLineEntity = JSON.parseObject(jsonObject.toString(), PurchaseOrderLineEntity.class);
        if (null == purchaseOrderLineEntity
                || StringUtils.isBlank(purchaseOrderLineEntity.getMaterialName().toString())
                || StringUtils.isBlank(purchaseOrderLineEntity.getSupplier().toString())
                || StringUtils.isBlank(purchaseOrderLineEntity.getPurchaseOrder().toString()) )
            return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参(物料名称、供应商、采购订单)！");
        /**
         * 物料ID
         */
        MaterialsEntity materialsEntity = new MaterialsEntity();
        materialsEntity.setName(purchaseOrderLineEntity.getMaterialName().toString());
        List<STDmaterielDTO> materialsInfo = materialsService.getMaterialsInfo(materialsEntity);
        if (null == materialsInfo
                || materialsInfo.size()<=0
                || StringUtils.isBlank(materialsInfo.get(0).getId()))return new ResponseResult(CommonCode.FAIL,"物料名称在物料配置表内没有数据，请核实！");
        purchaseOrderLineEntity.setMaterialName(materialsInfo.get(0).getId());

        /**
         * 供应商
         */
        SupplierInformationEntity supplierInformationEntity = new SupplierInformationEntity();
        supplierInformationEntity.setName(purchaseOrderLineEntity.getSupplier().toString());
        List<SupplierInformationDTO> supplierInfoInfo = supplierInfoService.getSupplierInfoInfo(supplierInformationEntity);
        if (null == supplierInfoInfo
                || supplierInfoInfo.size()<=0
                || StringUtils.isBlank(supplierInfoInfo.get(0).getId()))return new ResponseResult(CommonCode.FAIL,"供应商名称在供应商配置表内没有数据，请核实！");
        purchaseOrderLineEntity.setSupplier(supplierInfoInfo.get(0).getId());

        Boolean insertFlag = purchaseLineService.insertPurchaseLine(purchaseOrderLineEntity);
        if (!insertFlag){
            return new ResponseResult(CommonCode.FAIL,"采购订单行数据入库失败，请核实数据是否异常！");
        }
        return new ResponseResult(CommonCode.SUCCESS,"采购订单行数据入库成功");
    }

    /**
     * 共享库存数据入表
     *
     * @param json
     * @return
     */
    @Override
    public ResponseResult insertShareInventInfo(String json) {
        if (StringUtils.isBlank(json))return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参！");
        JSONObject jsonObject = JsonUtil.jsonStrToJson(json);
        SharedInventEntity sharedInventEntity = JSON.parseObject(jsonObject.toString(), SharedInventEntity.class);

        if (null == sharedInventEntity
                || StringUtils.isBlank(sharedInventEntity.getMaterialName().toString())
                || StringUtils.isBlank(sharedInventEntity.getCostCenter().toString()) )
            return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参(物料名称、成本中心、调配数量)！");
        /**
         * 物料ID
         */
        MaterialsEntity materialsEntity = new MaterialsEntity();
        materialsEntity.setName(sharedInventEntity.getMaterialName().toString());
        List<STDmaterielDTO> materialsInfo = materialsService.getMaterialsInfo(materialsEntity);
        if (null == materialsInfo
                || materialsInfo.size()<=0
                || StringUtils.isBlank(materialsInfo.get(0).getId()))return new ResponseResult(CommonCode.FAIL,"物料名称在物料配置表内没有数据，请核实！");
        sharedInventEntity.setMaterialName(materialsInfo.get(0).getId());
        /**
         * 成本中心ID
         */
        CostCenterEntity costCenterEntity = new CostCenterEntity();
        costCenterEntity.setName(sharedInventEntity.getCostCenter().toString());
        List<CostCenterDTOResponse> costCenterInfo = costCenterService.getCostCenterInfo(costCenterEntity);
        if (null == costCenterInfo
                || costCenterInfo.size()<=0
                || StringUtils.isBlank(costCenterInfo.get(0).getId()))return new ResponseResult(CommonCode.FAIL,"成本中心Id在成本中心配置表内没有数据，请核实！");
        sharedInventEntity.setCostCenter(costCenterInfo.get(0).getId());

        Boolean insertFlag = sharedInventService.insertSharedInventInfo(sharedInventEntity);
        if (!insertFlag){
            return new ResponseResult(CommonCode.FAIL,"共享库存数据入库失败，请核实数据是否异常！");
        }
        return new ResponseResult(CommonCode.SUCCESS,"共享库存数据入库成功");

    }

    /**
     * 查询请购单行和询价单信息
     *
     * @param reqLineEntity
     * @return
     */
    @Override
    public ResponseResult getreqRFQInfo(ReqLineEntity reqLineEntity) {
        List<PMSpurchaseApplyLineDTOResponse> reLineInfo = reLineService.getReLineInfo(reqLineEntity);
        if (null == reLineInfo || reLineInfo.size()<=0)return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        ArrayList<Object> reList = new ArrayList<>();
        /**
         * 多线程处理数据
         */
        ExecutorService pool = Executors.newCachedThreadPool();
        CountDownLatch latch = new CountDownLatch(reLineInfo.size());
        for (PMSpurchaseApplyLineDTOResponse reLineData : reLineInfo){
            /**
             * 开启子线程
             */
            Runnable run = new Runnable() {
                public void run() {
                    try {
                        HashMap<String, Object> reHashMap = new HashMap<>();
                        reHashMap.put("reqline",reLineData);

                        Object inquiryLine = reLineData.getInquiryLine();
                        if (null == inquiryLine)return;
                        InquiryOrderLineEntity inquiryOrderLineEntity = new InquiryOrderLineEntity();
                        inquiryOrderLineEntity.setId(inquiryLine.toString());
                        List<InquiryLineDTOResponse> inquiryOrderLineInfo = inquiryOrderLineService.getInquiryOrderLineInfo(inquiryOrderLineEntity);
                        if (null == inquiryOrderLineInfo || inquiryOrderLineInfo.size()<=0)return;
                        List<InquiryOrderLineEntity> inquiryOrderLineEntities = inquiryOrderLineService.InquiryOrderLineDataConver(inquiryOrderLineInfo);
                        if (null == inquiryOrderLineEntities || inquiryOrderLineEntities.size()<=0)return;

                        reHashMap.put("inquiryOrderLine",inquiryOrderLineEntities);
                        reList.add(reHashMap);
                    }catch(Exception e){
                        log.info("多线程转换报错,查询对象是：【{}】,请检查：【{}】",reLineData,e);
                    } finally {
                        latch.countDown();
                    }
                }
            };
            pool.execute(run);
        }try {
            latch.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.info("多线程转换报错,请检查：【{}】",e);
        }finally {
            pool.shutdown();
        }
        return new ResponseResult(CommonCode.SUCCESS,reList);
    }

    /**
     * 甄选对象数据入库
     *
     * @param json
     * @return
     */
    @Override
    public ResponseResult insertSelectionInfo(String json) {
        if (StringUtils.isBlank(json))return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参！");
        JSONObject jsonObject = JsonUtil.jsonStrToJson(json);
        SrmSelectEntity srmSelectEntity = JSON.parseObject(jsonObject.toString(), SrmSelectEntity.class);
        boolean insertInfo = selectionService.insertSelectionInfo(srmSelectEntity);
        if (!insertInfo){
            return new ResponseResult(CommonCode.FAIL,"甄选数据入库失败，请核实数据是否异常！");
        }
        return new ResponseResult(CommonCode.SUCCESS,"甄选数据入库成功");
    }

    /**
     * 物料资料对象数据入库
     *
     * @param json
     * @return
     */
    @Override
    public ResponseResult insertMaterielInfo(String json) {
        if (StringUtils.isBlank(json))return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参！");
        JSONObject jsonObject = JsonUtil.jsonStrToJson(json);
        MaterialsEntity materialsEntity = JSON.parseObject(jsonObject.toString(), MaterialsEntity.class);
        boolean insertInfo = materialsService.insertMaterialInfo(materialsEntity);
        if (!insertInfo){
            return new ResponseResult(CommonCode.FAIL,"甄选数据入库失败，请核实数据是否异常！");
        }
        return new ResponseResult(CommonCode.SUCCESS,"甄选数据入库成功");
    }

    /**
     * 查询供应商对象数据信息
     *
     * @param supplierInformationEntity
     * @return
     */
    @Override
    public ResponseResult getSupplierInfo(SupplierInformationEntity supplierInformationEntity) {
        List<SupplierInformationDTO> supplierInfoInfo = supplierInfoService.getSupplierInfoInfo(supplierInformationEntity);
        if (null == supplierInfoInfo || supplierInfoInfo.size()<=0)return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        List<SupplierInformationEntity> supplierInformationEntities = supplierInfoService.supplierInfoDataConver(supplierInfoInfo);
        if (null == supplierInformationEntities || supplierInformationEntities.size()<=0)return new ResponseResult(CommonCode.FAIL,new ArrayList<>());
        return new ResponseResult(CommonCode.SUCCESS,supplierInformationEntities);
    }

    /**
     * 查询采购订单行对象数据信息
     *
     * @param purchaseOrderEntity
     * @return ResponseResult
     */
    @Override
    public ResponseResult getPurchaseLineInfo(PurchaseOrderEntity purchaseOrderEntity) {
        if (null == purchaseOrderEntity
                || StringUtils.isBlank(purchaseOrderEntity.getSupplierStatus())){
            purchaseOrderEntity.setSupplierStatus("已受理");
        }
        ArrayList<Object> reList = new ArrayList<>();
        List<PurchaseOrderDTOResponse> purchaseOrderInfo = purchaseOrderService.getPurchaseOrderInfo(purchaseOrderEntity);
        if (null == purchaseOrderInfo || purchaseOrderInfo.size()<=0)return new ResponseResult(CommonCode.FAIL,"没有查询到对应的采购订单数据！");
        /**
         * 多线程处理数据
         */
        ExecutorService pool = Executors.newCachedThreadPool();
        CountDownLatch latch = new CountDownLatch(purchaseOrderInfo.size());
        for (PurchaseOrderDTOResponse purData : purchaseOrderInfo){
            /**
             * 开启子线程
             */
            Runnable run = new Runnable() {
                public void run() {
                    try {
                        if (StringUtils.isBlank(purData.getId()))return;
                        PurchaseOrderLineEntity purchaseOrderLineEntity = new PurchaseOrderLineEntity();
                        purchaseOrderLineEntity.setPurchaseOrder(purData.getId());
                        List<PurchaseLineDTOResponse> purchaseLineInfo = purchaseLineService.getPurchaseLineInfo(purchaseOrderLineEntity);
                        if (null == purchaseLineInfo || purchaseLineInfo.size()<=0)return;
                        List<PurchaseOrderLineEntity> purchaseOrderLineEntities = purchaseLineService.purchaseLineDataConver(purchaseLineInfo);
                        if (null == purchaseOrderLineEntities || purchaseOrderLineEntities.size()<=0)return;
                        /**
                         * 多线程处理数据
                         */
                        ExecutorService poolChild = Executors.newCachedThreadPool();
                        CountDownLatch latchChild = new CountDownLatch(purchaseOrderLineEntities.size());
                        for (PurchaseOrderLineEntity purLine : purchaseOrderLineEntities){
                            /**
                             * 开启子线程
                             */
                            Runnable run = new Runnable() {
                                public void run() {
                                    try {
                                        if (null == purLine.getMaterialName()
                                                || null == purLine.getUnit()
                                                || null == purLine.getSupplier())return;
                                        /**
                                         * 物料名称
                                         */
                                        MaterialsEntity materialsEntity = new MaterialsEntity();
                                        materialsEntity.setId(purLine.getMaterialName().toString());
                                        List<STDmaterielDTO> materialsInfo = materialsService.getMaterialsInfo(materialsEntity);
                                        if (null == materialsInfo || materialsInfo.size()<=0)return;
                                        purLine.setMaterialName(materialsInfo.get(0).getName());
                                        /**
                                         * 单位名称
                                         */
                                        UnitEntity unitEntity = new UnitEntity();
                                        unitEntity.setId(purLine.getUnit().toString());
                                        List<UnitDTOResponse> unitInfo = unitService.getUnitInfo(unitEntity);
                                        if (null == unitInfo || unitInfo.size()<=0)return;
                                        purLine.setUnit(unitInfo.get(0).getName());
                                        /**
                                         * 供应商名称
                                         */
                                        SupplierInformationEntity supplierInformationEntity = new SupplierInformationEntity();
                                        supplierInformationEntity.setId(purLine.getSupplier().toString());
                                        List<SupplierInformationDTO> supplierInfoInfo = supplierInfoService.getSupplierInfoInfo(supplierInformationEntity);
                                        if (null == supplierInfoInfo || supplierInfoInfo.size()<=0)return;
                                        purLine.setSupplier(supplierInfoInfo.get(0).getName());

                                        reList.add(purLine);
                                    }catch(Exception e){
                                        log.info("多线程转换报错,查询对象是：【{}】,请检查：【{}】",purData,e);
                                    } finally {
                                        latchChild.countDown();
                                    }
                                }
                            };
                            poolChild.execute(run);
                        }try {
                            latchChild.await(10, TimeUnit.SECONDS);
                        } catch (InterruptedException e) {
                            log.info("多线程转换报错,请检查：【{}】",e);
                        }finally {
                            poolChild.shutdown();
                        }

                    }catch(Exception e){
                        log.info("多线程转换报错,查询对象是：【{}】,请检查：【{}】",purData,e);
                    } finally {
                        latch.countDown();
                    }
                }
            };
            pool.execute(run);
        }try {
            latch.await(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.info("多线程转换报错,请检查：【{}】",e);
        }finally {
            pool.shutdown();
        }
        return new ResponseResult(CommonCode.SUCCESS,reList);
    }

    /**
     * 写入入库单对象数据
     *
     * @param json
     * @return
     */
    @Override
    public ResponseResult insertStockInOrderInfo(String json) {
        if (StringUtils.isBlank(json))return new ResponseResult(CommonCode.FAIL,"传入的入参为空，请检查入参！");
        JSONObject jsonObject = JsonUtil.jsonStrToJson(json);
        StockInOrderEntity stockInOrderEntity = JSON.parseObject(jsonObject.toString(), StockInOrderEntity.class);
        boolean insertInfo = stockInOrderService.insertStockInOrderInfo(stockInOrderEntity);
        if (!insertInfo){
            return new ResponseResult(CommonCode.FAIL,"入库单数据入库失败，请核实数据是否异常！");
        }
        return new ResponseResult(CommonCode.SUCCESS,"入库单数据入库成功");
    }
}
